<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
  <script src="js/script_thinhnc.js"></script>
  <script>
  
  </script>
  </head>
<?php
ob_start();
include('connect/connect.php');
check_admin();
$today = date("h:i a d/m/y ");
$result2 = mysql_query('SELECT * FROM tbl_lop');
$result = mysql_query('SELECT * FROM tbl_giangvien');
$sql_query = @mysql_query("SELECT * FROM user WHERE id={$_SESSION['user_id']}");
$member = @mysql_fetch_array($sql_query);
if (isset($_POST['content']))
  $result4 = "INSERT INTO comment (comment, date, mhs, author) 
VALUES ('" . $_POST['content'] . "', '" . $today . "' , '" . $_POST['mhs'] . "' , '" . $member['user'] . "' )";
?>
<style>
  *{margin:0px; padding:0px;}
  label{
    display:block;
    width:200px;
    float:left;
  }
  .submit{
    width:100px;
    margin-left:50px;
  }
  .comment{
    background-color: white;
    padding-left:100px;
    font-family:Tahoma, Geneva, sans-serif
  }
  .mhs{
    display:none;
  }
  .tablecomment{
    margin: 30px;
    background-color: #FFFF99;
  }

</style>
<?php
echo "Update DATA!<br />";
$s = @mysql_query("SELECT * FROM `tbl_thuphieu`");
if (mysql_num_rows($s) > 0) {
  //Form nhap lieu
  ?>
  <div id="main">
    <form action="edit.phieuthu.php" method="POST" name="update" id="update">
	<input type="hidden" name="ajaxSwitcher" value="1" />

      <?php
      if (isset($_GET['stt']) != "") {
        //Hien bang info
        echo "<table style='border:1px solid green;'>
		<h2>Thong tin</h2>
		";
        $z = @mysql_query("SELECT * FROM `tbl_thuphieu` WHERE `f_maphieu` = '" . $_GET['stt'] . "';");
        while ($r = mysql_fetch_array($z)) {
          echo "
		<tr style='border:1px solid green;'>
			";
          for ($j = 0; $j
              <= 31; $j++) {
            echo "<td style='border:1px solid green;'>" . $r[$j] . "</td>
			";
          }
          echo "
		</tr>
		";
          echo "
	</table>
	";
          //Hien form edit
          ?>
          <br />
          <h2>UPDATE</h2>
          <input name="f_maphieu_" type="hidden" value="<?php echo $r['f_maphieu']; ?>" />
          <input name="check_ok" type="hidden" value="1" />
          <br />
          <label>Maphieu</label>
          <?php echo $r['f_maphieu']; ?>
          <br />
          <label>Mahocvien</label>
          <input type="text" name="mahocvien" value="<?php echo $r['f_mahocvien']; ?>" />
          <br />
          <label>Gioitinh</label>
          <select name="gioitinh">
            <?php echo $r['f_gioitinh']; ?>
            <option value="0"   <?php if ($r['f_gioitinh'] == 0) {
        echo ' selected';
      } ?>>Nam</option>
            <option value="1" <?php if ($r['f_gioitinh'] == 1) {
        echo ' selected';
      } ?>>Nu</option>
          </select>
          <br />
          <label>Nghe Nghiep</label>
          <select name="nghenghiep">
      <?php echo $r['f_nghenghiep']; ?>
            <option value="1" <?php if ($r['f_nghenghiep'] == 1) {
        echo ' selected';
      } ?>>Sinh Vien</option>
            <option value="2" <?php if ($r['f_nghenghiep'] == 2) {
        echo ' selected';
      } ?>>Ke toan vien</option>
            <option value="3" <?php if ($r['f_nghenghiep'] == 3) {
        echo ' selected';
      } ?>>Chu doanh nghiep</option>
            <option value="4" <?php if ($r['f_nghenghiep'] == 4) {
        echo ' selected';
      } ?>>Dac biet</option>
          </select>
          <br />
          <label>Ngaysinh</label>
          <input type="text" name="ngaysinh" value="<?php echo $r['f_ngaysinh']; ?>" />
          <br />
          <label>Diachi</label>
          <input type="text" name="diachi" value="<?php echo $r['f_diachi']; ?>
" />
          <br />
          <label>Phone</label>
          <input type="text" name="phone" value="<?php echo $r['f_phone']; ?>
" />
          <br />
          <label>Loaihinh</label>
          <input type="text" name="loaihinh" value="<?php echo $r['f_loaihinh']; ?>
" />
          <br />
          <label>Khoa</label>
          <select size="1" name="khoa" onchange="if(this.selectedIndex==1){toggleAjax(0);loadGVFull();} else toggleAjax(1);">
            <option value="1" <?php if ($r['f_khoa'] == 1) {
        echo ' selected';
      } ?>>T&#7841;i nhà</option>
            <option value="2" <?php if ($r['f_khoa'] == 2) {
        echo ' selected';
      } ?>>T&#7853;p trung</option>
            <option value="3" <?php if ($r['f_khoa'] == 3) {
        echo ' selected';
      } ?>>H&#7885;c tr&#7921;c tuy&#7871;n</option>
          </select>
          <br />

          <label>Lop</label>
          <select name='lop' id='lop'>
      <?php
      while ($row2 = mysql_fetch_array($result2)) {
        if ($r['8'] == $row2['f_lop'])
          echo '<option value=' . $row2['f_lop'] . ' selected>' . $row2['f_lop'] . '</option>
	';
        else
          echo '
	<option value=' . $row2['f_lop'] . ' >' . $row2['f_lop'] . '</option>
	';
      }
      ?>
          </select>
          <br />
          <label>Hovaten</label>
          <input type="text" name="hovaten" value="<?php echo $r['f_hovaten']; ?>
" />
          <br />
          <label>Ngaybatdau</label>
		  <input type="hidden" name="old_ngaybatdau" value="<?php echo $r['f_ngaybatdau']; ?>" />
          <input type="text" name="f_ngaybatdau" value="<?php echo $r['f_ngaybatdau']; ?>" onBlur="tinhNgayKetThuc();timGiaoVien();" />
		  
		  <br />
          <label>Ngayketthuc</label>
		  <input type="hidden" name="old_ngayketthuc" value="<?php echo $r['f_ngayketthuc']; ?>" />
          <input type="text" name="f_ngayketthuc" value="<?php echo $r['f_ngayketthuc']; ?>" onChange="timGiaoVien();" />
          <br />
          <label>TKB</label>
		  <input type="<?php echo (strlen($r['f_tkb']) != 1 && $r['f_tkb'] != -1 && $r['f_ca'] != '') ? "text" : "hidden"; ?>" name="old_tkb" value="<?php echo $r['f_tkb']; ?>" />		  
		  <select name="f_tkb" class="required" onchange="tinhNgayKetThuc();timGiaoVien();">
					<option value="-1">Chọn TKB</option>
					<option value="1">2-4-6</option>
					<option value="2">3-5-7</option>
					<option value="3">T7-CN</option>
					<option value="4">CN</option>
					<option value="0">Cả tuần</option>
			</select>
          <br />
          <label>Ca</label>		  
		  <input type="<?php echo (strlen($r['f_ca']) != 1 && $r['f_ca'] != -1 && $r['f_ca'] != '') ? "text" : "hidden"; ?>" name="old_ca" value="<?php echo $r['f_ca']; ?>" />
		  <div style="float:left">
		  <select name="f_ca" class="required" onchange="showGioHoc(this.options[this.selectedIndex].value);tinhNgayKetThuc();timGiaoVien();">
					<option value="1">Sáng</option>
					<option value="2">Chiều</option>
					<option value="3">Tối</option>
					<option value="0">Khác</option>
		  </select>
		  </div>
		  <input type="hidden" name="old_hstart" value="<?php echo $r['f_giobatdau']; ?>" onChange="tinhNgayKetThuc();timGiaoVien();" />
		  <input type="hidden" name="old_hend" value="<?php echo $r['f_gioketthuc']; ?>" onChange="tinhNgayKetThuc();timGiaoVien();"  />
		<div id="showgiohoc" style="float:left;padding-left: 20px;"></div>
		<div style="clear:both"></div>
		<script>
			// Tu dong chon gia tri "thoi khoa bieu" duoc chon trong database
			f_tkb = document.forms['update']['f_tkb'].options;
			tkb = document.forms['update']['old_tkb'];

			for (i = 0; i < f_tkb.length; i++) {				
				if (f_tkb[i].value == tkb.value)
				{
					f_tkb[i].selected = true;
				}					
			}	
			// Tu dong chon gia tri "ca" duoc chon trong database
			f_ca = document.forms['update']['f_ca'].options;
			ca = document.forms['update']['old_ca'];

			for (i = 0; i < f_ca.length; i++) {				
				if (f_ca[i].value == ca.value)
				{
					f_ca[i].selected = true;
				}					
			}			
			
			showGioHoc(<?php echo $r['f_ca']; ?>);
			// Tu dong chon gia tri thoi gian (from...to...) duoc chon trong database
			f_hstart = document.forms['update']['f_hstart'].options;
			giobatdau = <?php echo $r['f_giobatdau']; ?>;
			
			for (i = 0; i < f_hstart.length; i++) {
				if (f_hstart[i].value == giobatdau)
				{
					f_hstart[i].selected = true;
				}					
			}
			
			f_hend = document.forms['update']['f_hend'].options;
			gioketthuc = <?php echo $r['f_gioketthuc']; ?>;
			
			for (i = 0; i < f_hend.length; i++) {
				if (f_hend[i].value == gioketthuc)
				{
					f_hend[i].selected = true;
				}					
			}
		</script>
		<label>Số buổi</label>
		<input type="hidden" name="old_sobuoi" value="<?php echo $r['f_sobuoi']; ?>" />
		<input type="text" name="f_sobuoi" value="<?php echo $r['f_sobuoi']; ?>" onblur="tinhNgayKetThuc();timGiaoVien();" />	
          <br />
		 <label>Giangvien</label>
		 <input type="hidden" name="old_giangvienid" value="<?php echo $r['f_giangvien']; ?>" />
		 <input type="hidden" name="old_tengiangvien" value="<?php echo $r['f_tengiangvien']; ?>" />
		 <input type="hidden" name="showoldgv" value="1" />
		  <div id="timgv" style="float:left">		  
          <select name="f_giangvien">
      <?
			// hien ten giang vien hien tai
			echo "<option value=\"".$r['f_giangvien']."\">";
			echo $r['f_tengiangvien'];
			echo "</option>";
      ?>
          </select></div>
		  <script>timGiaoVien();		   
		  </script>
          <br />
          <label>Số nhà</label>
          <input type="text" name="dkbd_loaihinh" value="<?php echo $r['f_sonha']; ?>
" />
          <br />
          <label>Phường</label>
          <input type="text" name="dkbd_khoa" value="<?php echo $r['f_phuong']; ?>
" />
          <br />
          <label>Quận</label>
          <input type="text" name="dkbd_lop" value="<?php echo $r['f_quan']; ?>
" />
          <br />
          <label>Thành phố</label>
          <input type="text" name="dkbd_ngaybatdau" value="<?php echo $r['f_tp']; ?>
" />
          <br />
          <label>Email</label>
          <input type="text" name="dkbd_tkb" value="<?php echo $r['f_email']; ?>
" />
          <br />

          <label>Nguoitao</label>
          <input type="text" name="nguoitao" value="<?php echo $r['f_nguoitao']; ?>
" />
          <br />
          <label>Muchp</label>
          <input type="text" name="muchp" value="<?php echo $r['f_muchp']; ?>
" />
          <br />
          <label>Tienhp</label>
          <input type="text" name="tienhp" value="<?php echo $r['f_tienhp']; ?>
" />
          <br />
          <label>Tiengt</label>
          <input type="text" name="tiengt" value="<?php echo $r['f_tiengt']; ?>
" />
          <br />
          <label>TienCD</label>
          <input type="text" name="tiencd" value="<?php echo $r['f_tiencd']; ?>
" />
          <br />
          <label>Miengiam</label>
          <input type="text" name="miengiam" value="<?php echo $r['f_miengiam']; ?>
" />
          <br />
          <label>Thucthu</label>
          <input type="text" name="thucthu" value="<?php echo $r['f_thucthu']; ?>
" />
          <br />
          <label>Lydo</label>
          <input type="text" name="lydo" value="<?php echo $r['f_lydo']; ?>
" />
          <br />
          <label>Ngaytao</label>
          <input type="text" name="ngaytao" value="<?php echo $r['f_ngaytao']; ?>
" />
          <br />          
          <br />
          <label>Trangthai</label>
          <select size="1" name="trangthai" onchange="doenable(this.value)">
            <option value="1" <?php if ($r['f_trangthai'] == 1) {
        echo ' selected';
      } ?>>&#272;ã thanh toán</option>
            <option value="2" <?php if ($r['f_trangthai'] == 2) {
        echo ' selected';
      } ?>>Khách hàng đã đặt cọc</option>
            <option value="3" <?php if ($r['f_trangthai'] == 3) {
        echo ' selected';
      } ?>>Khách hàng ti&#7873;m n&#259;ng</option>
            <option value="4" <?php if ($r['f_trangthai'] == 4) {
        echo ' selected';
      } ?>>H&#7911;y</option>
          </select>
          <br />
          <label>Hoahong</label>
          <input type="text" name="hoahong" value="<?php echo $r['f_hoahong']; ?>
" />
          <br />
          <label>File</label>
          <input type="text" name="file" value="<?php echo $r['file']; ?>
" />
          <br />
          Bổ sung thêm
          <textarea rows="7" name="dkbd_ca" cols="41">
          <?php echo $r['f_dkbd_ca']; ?></textarea>
          <br />
          <?php
        }
        ?>
        <!--hidden content-->
        <input type=hidden class="lmhv" name="lmhv" value="<?php echo $_GET['stt'] ?>
               ">
        <input type=hidden class="nguoisua" name="nguoisua" value="<?php echo $member['user'] ?>
               ">
        <input type=hidden class="ngay" name="ngay" value="<?php echo $today ?>
               ">
        <!--Proccess-->
        <input type="submit" name="ok" />
      </form>
      <!-- End #update -->
      <br>
      <div class="comment">
        <br>
        <?php
        if($_SESSION['user_admin']!=3){
        $result = mysql_query("SELECT * FROM comment WHERE mhs=" . $_GET['stt'] . " ORDER BY id DESC");
        echo '<div class=tablecomment>';
        while ($row = mysql_fetch_array($result)) {
          if ($_SESSION['user_admin'] == 1)
            echo " <b><li>" . $row['author'] . '(' . $row['date'] . ')</b>:' . $row['comment'] . "<a href='delete.comment.php?stt=" . $row['id'] . "'>(Xóa)</a>";
          else
            echo " <b><li>" . $row['author'] . '  (' . $row['date'] . ')</b> :' . $row['comment'];
          echo "<br />";
        }
        echo '</div>';
        //echo $result4;
        if (isset($_POST['content'])) {
          if (mysql_query($result4)) {      
          }
          else {
            echo "Error!!";
          }
        }
      }?>
        <form color=blue method=POST action=#>

          <input type=text class="mhs" name="mhs" value="<?php echo $_GET['stt'] ?>
                 ">
          Comment:
          <br>
          <textarea cols="30" id="content" name="content"></textarea>
          <br>
          <input type="submit" class="submit"></form>
    <?php echo '<a href="log.php?stt=' . $_GET['stt'] . '">
<button type="button">Log</button>
</a>
' ?>
      </div>
    </div>
    <?php
  }
}
?>